package com.ziyun.pop.modules.erpSupplierOffline.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.modules.erpSupplierOffline.entity.ErpSupplierStateEnum;
import com.ziyun.pop.modules.freightages.entity.SdbEctoolsRegionsEntity;
import com.ziyun.pop.modules.order.service.ErpOrderService;
import io.renren.common.utils.R;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.pop.modules.erpSupplierOffline.dao.ErpSupplierOfflineDao;
import com.ziyun.pop.modules.erpSupplierOffline.entity.ErpSupplierOfflineEntity;
import com.ziyun.pop.modules.erpSupplierOffline.service.ErpSupplierOfflineService;


@Service("erpSupplierOfflineService")
public class ErpSupplierOfflineServiceImpl extends ServiceImpl<ErpSupplierOfflineDao, ErpSupplierOfflineEntity> implements ErpSupplierOfflineService {
    // 查询省市区级联数据
    @Autowired
    private ErpOrderService erpOrderService;


  @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ErpSupplierOfflineEntity> page = (Page<ErpSupplierOfflineEntity>) this.page(
                new Query<ErpSupplierOfflineEntity>(params).getPage(),
                new QueryWrapper<ErpSupplierOfflineEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ErpSupplierOfflineEntity> getListBySupplierName(String ziyunSuppName) {
        return this.baseMapper.getListBySupplierName(ziyunSuppName);
    }

    @Override
    public R queryPageErpSupplierList(Map<String, Object> params) {
       /* String supplierName = (String) params.get("supplierName");
        String state = (String) params.get("state");
        String contactName = (String) params.get("contactName");*//*
        Integer page=Integer.parseInt(params.get("page").toString())-1;
        Integer pageSize=Integer.parseInt(params.get("limit").toString());
        Page page1 = new Page(page, pageSize);
        List<ErpSupplierOfflineEntity> list= this.baseMapper.selectErpSupplierOffline(page1,params);
        // 查询省市区级联数据
        List<String> regions = erpOrderService.queryRegionsSascade();
        // 存放枚举类到userdata
        Map<String, Object> userDataMap = new HashMap<>();
        userDataMap.put("erpSupplierStateEnum", JsonUtils.enumToList(ErpSupplierStateEnum.class));
        userDataMap.put("regions", JSONArray.fromObject(regions).toString());

        Integer totalCount=list.size();
        PageUtils pageUtils=new PageUtils(list,totalCount,pageSize,page);
        return R.ok().put("page", pageUtils)
                .put("userData", userDataMap);*/
        return  R.ok();
    }

    @Override
    public ErpSupplierOfflineEntity selectByProduId(Integer supplierId) {
        return this.baseMapper.selectByProduId(supplierId);
    }

    @Override
    public R updateByMap(Map<String, Object> map) {
      this.baseMapper.updateByMap(map);
      return R.ok();
    }

    @Override
    public int selectCountBySupplierName(String supplierName) {
        return this.baseMapper.selectCountBySupplierName(supplierName);
    }

    @Override
    public int selectCountByTel(String contactTel) {
        return this.baseMapper.selectCountByTel(contactTel);
    }


}
